package com.bishe.serivce.Impl;

import cn.hutool.core.util.StrUtil;
import com.bishe.dao.MessageDao;
import com.bishe.pojo.Message;
import com.bishe.serivce.IMessageService;
import com.bishe.utils.JobUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * 消息接口实现
 * @date 2022/03/20 42:08:24
 */
@Service
public class MessageServiceImpl implements IMessageService {
    @Autowired
    private MessageDao messageDao;

    @Override
    public List<Message> findAll() {
        return messageDao.findAll();
    }

    @Override
    public Message findById(String id) {
        return messageDao.findById(id);
    }

    @Override
    public void deleteById(String id) {
        messageDao.deleteById(id);
    }

    @Override
    public void updateById(Message message) {
        messageDao.updateById(message);
    }

    @Override
    public void save(Message message) {
        messageDao.save(message);
    }

    @Override
    public void addOrUpdate(Message message, HttpServletRequest httpServletRequest) {
        //保存
        if (StrUtil.isEmpty(message.getId())|| findById(message.getId()) == null){
            message.setId(StrUtil.uuid());
            message.setCreateTime(new Date());
            save(message);
            return;
        }
        //修改
        updateById(message);
    }
}